﻿using Kavaa.Core.Data;
using Kavaa.Modules.PortailMedical.Entity;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace Kavaa.Modules.PortailMedical.Datalayer
{
    internal static class CategorieDAO
    {



        public static Categories Getblocs(int cliniqueId,int  acteId)
        {
            Categories Categories = new Categories();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetBlocsClinique]"
            , new List<SqlParameter>() { 
                new SqlParameter("@acteId", acteId),
                new SqlParameter("@cliniqueId" , cliniqueId),
               
            }))
            {
                Categories.Add(new Categorie()
                {
                    Id = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0,
                    Name = (row["Name"] != DBNull.Value) ? Convert.ToString(row["Name"]) : null,
                   
                });
            }

             return Categories;
        }

        public static Proprietes GetProprietesCategorie(int id_categorie)
        {
            Proprietes Proprietes = new Proprietes();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetProprietesCategorie]"
            , new List<SqlParameter>() { 
                new SqlParameter("@CategorieId", id_categorie),
               
               
            }))
            {
                Proprietes.Add(new Propriete()
                {
                    Id = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0,
                    Name = (row["Name"] != DBNull.Value) ? Convert.ToString(row["Name"]) : null,
                    Value = (row["Value"] != DBNull.Value) ? Convert.ToString(row["Value"]) : null,

                });
            }

                return Proprietes;

        }
        public static void SaveActesCategorie(int ActeId, int CategorieId)
        {
            SqlDaoAdapter.ExecuteNonQuery(ConfigurationCache.DatabaseConnectionString,
              "[dbo].[sp_PortailMedical_SaveActesCategorie]"
          , new List<SqlParameter>() { 
                new SqlParameter("@ActeId", ActeId),
                new SqlParameter("@CategorieId", CategorieId)
              
               
            });
        }
        public static int SaveCategorie(String Categorie, int RessourceCliniqueId)
        {
            int ID = 0;
            foreach (var row in

            SqlDaoAdapter.ExecuteReader(ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_SaveCategorie]"
            , new List<SqlParameter>() { 
                      new SqlParameter("@Categorie", Categorie),
                new SqlParameter("@RessourceCliniqueId", RessourceCliniqueId)
               
            }))
            { ID = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0; }

            return ID;





        }

        public static Categories GetRessourcesClinique(int CliniqueId)
        {
            Categories Categories = new Categories();
            int idcat;
            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetRessourcesClinique]"
            , new List<SqlParameter>() { 
               new SqlParameter("@CliniqueId" , CliniqueId),
               
            }))
            {
                idcat = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0;
                Categories.Add(new Categorie()
                {
                    Id = (row["ID"] != DBNull.Value) ? Convert.ToInt32(row["ID"]) : 0,
                    Name = (row["CategorieName"] != DBNull.Value) ? Convert.ToString(row["CategorieName"]) : null,
                    etat = (row["etat"] != DBNull.Value) ? Convert.ToInt32(row["etat"]) : 0,
                    RessourceClinique = new RessourceClinique() { Ressource = new Ressource() { Name = (row["RessourceName"] != DBNull.Value) ? Convert.ToString(row["RessourceName"]) : null, } },

                    Proprietes = GetProprietesCategorie(idcat),

                });
            }

            return Categories;
        }
    }
}
